class Solution {
public:
    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {
        int n = nums1.size();
        sort(nums1.begin(), nums1.end());
        sort(nums2.begin(), nums2.end());
        //4 8 12 16 20
        //10 14 18

        //3 3 5 5
        //7 7
        for (int i = 2; i >= 0; i--) {
            int x = nums2[0] - nums1[i];
            cout << "x==" << x << endl;
            int cnt = 0;
            int j = 0;
            for (int k = 0; k < n; k++) {
                if (j >= n - 2)continue;
                if (nums2[j] - nums1[k] == x)j++;
                else cnt++;
            }
            if (cnt <= 2)return x;
        }
        return 0;
        //2 5 6 7 7 8 10 10
        //3 4 5 5 8 8
    }
};